package com.tom.feign.clients;

import com.tom.domain.Login;
import com.tom.dto.LoginAndMealIdDto;
import com.tom.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 降级类
 */
@Component
@Slf4j
public class FallbackFactorySystem implements FallbackFactory<LoginFeignClient> {

    @Override
    public LoginFeignClient create(Throwable throwable) {
        return new LoginFeignClient() {
            @Override
            public AjaxResult save(Login login) {
                log.error("认证异常{}",throwable.getMessage());
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("认证失败");
            }

            @Override
            public AjaxResult saveLoginAndMeal(LoginAndMealIdDto loginAndMealIdDto) {
                log.error("认证异常{}",throwable.getMessage());
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("认证失败");
            }
        };
    }
}
